<!-- 
    @file: 首页技术模块组件
    @auth: lizibin
 -->
<template>
    <div class="technology" v-loading="loading" element-loading-text="玩命加载中...">
        <div class="technology_title">
            <h3 class="title"><b>技术</b></h3>
        </div>
        <div class="technology_layout">
            <div v-for="(item, index) in articleInfo">
                <div class="contentBox item">
                    <div @click="RouterJump('articleDetails', item.articleId)" class="articleBox-jump"
                        :title="item.articleTitle">
                        <div class="articleContent">
                            <h4 class="title">{{ item.articleTitle }}</h4>
                            <p>{{ item.articleClassifyName }} · {{ item.publishTime }}</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
<script lang="ts" setup>
import {
    onMounted,
    reactive,
} from "vue";
import { Reactive } from '@/types/articleTypes'
import { storeToRefs } from 'pinia'
import { useStore } from '@/store/index'
import { SystemSetupHandle, ArticleFiltterBySystem } from '@/utils/utils'
import {
    useRouter,
    useRoute
} from 'vue-router';
const router = useRouter()
const RouterJump = (name: string, val: number) => {
    router.push({
        path: name,
        query: {
            id: val
        }
    })
}

const Store = useStore()
const { SystemSetup, AllArticleInfo } = storeToRefs(Store)

const state = reactive<Reactive>({
    // 筛选出来的文章内容
    articleInfo: [],
    loading: false
});

const loadData = async (state: Reactive) => {
    state.loading = true;

    // 设置
    const { code, data } = SystemSetup.value;
    // 全部文章
    const { code: ACode, data: AData } = AllArticleInfo.value;
    // 技术区域的文章id，数组
    const technologyData = SystemSetupHandle(data.technologyArticle)
    // 筛选对应文章
    ArticleFiltterBySystem(technologyData, AData, state.articleInfo)
    state.loading = false;
}

//挂载后加载数据
onMounted(() => {
    loadData(state);
});

const { articleInfo, loading } = state;
</script>

<style scoped>
.technology {
    background: rgb(255, 255, 255);
    border-radius: 6px;
    padding: 20px;
    margin-bottom: 20px;
}

.technology_title {
    margin-bottom: 15px;
    margin-top: -10px;
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid rgb(238, 238, 238);
    overflow: hidden;
}

.technology_title .title {
    line-height: 40px;
    color: #474749;
}

.technology_title .title b {
    display: inline-block;
    border-bottom: 4px solid #2fa7b9;
}

.articleBox-jump {
    cursor: pointer;
}

.technology_layout .contentBox {
    margin-bottom: 15px;
    position: relative;
    overflow: hidden;
    font-size: 12px;
    color: #999;
    line-height: 18px;
}

.technology_layout .contentBox h4:hover {
    color: #2fa7b9;
}

.technology_layout .contentBox span {
    cursor: pointer;
}

.technology_layout .title {
    font-size: 14px;
    line-height: 24px;
    margin-bottom: 10px;
    color: #454545;
}

.technology_layout p {
    font-size: 12px;
    color: #999;
}

.technology_layout .contentBox.item {
    padding: 10px 0;
    border-bottom: 1px solid #eee;
}

.technology_layout .contentBox.item .title {
    font-size: 15px;
    overflow: hidden;
    -webkit-box-orient: vertical;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    text-align: justify;
    cursor: pointer;
    line-height: 20px;
    color: #727272;
}

.technology_layout .contentBox.item .title:hover {
    color: #2fa7b9;
}

.articleContent {
    width: 100%;
    float: left;
    word-break: break-all;
    text-align: justify;
}
</style>